<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%--
  Created by IntelliJ IDEA.
  User: 18134216985
  Date: 2024-04-08
  Time: 18:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <script src="/webjars/layui/2.6.8/layui.js"></script>
    <link rel="stylesheet" href="/webjars/layui/2.6.8/css/layui.css">
    <title>Title</title>
</head>
<body>
<%--条件查询--%>
<div class="layui-collapse">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">查询条件</h2>
        <div class="layui-colla-content layui-show">
            <div class="layui-form"  id="searchForm" lay-filter="searchForm">
                <div class="layui-inline">
                    <input name="repairsType" class="layui-input" placeholder="维修类型">
                </div>
                <div class="layui-inline">
                    <input name="position" class="layui-input" placeholder="维修位置">
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" onclick="search()" >查询</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="barDemo">
    <button class='layui-btn layui-btn-sm layui-btn-normal' lay-event='finish'>完成</button>
    <button class='layui-btn layui-btn-sm layui-btn-normal' lay-event='repai'>退单</button>
</script>
</script>
<table class="layui-hide" id="ID-table-demo-data" lay-filter="itemTable"></table>
<%--完成页面--%>
<div id="updateState" style="display:none;padding:20px">
    <form class="layui-form" id="updateStateForm" lay-filter="updateState">
        <div class="layui-inline">
            <input type="hidden" name="id" class="layui-input" placeholder="编号">
        </div>
        <div class="layui-inline">
            <input type="hidden" name="repstateid" class="layui-input" placeholder="状态">
        </div>
        <div class="layui-form-item">
                <input type="text" name="money" id="moneys" lay-verify="required" placeholder="请输入价格" class="layui-input">
        </div>

        <h3 style="text-align: center">恭喜你完成任务</h3>
    </form>
</div>
<div id="addMoney" style="display:none;padding:20px">
    <form class="layui-form" id="addMoneyForm" lay-filter="addMoneyForm">
        <div class="layui-inline">
            <input type="text" name="repairpeople" class="layui-input" placeholder="业主编号">
        </div>
        <div class="layui-inline">
            <input type="text" name="phone" class="layui-input" placeholder="状态">
        </div>
        <div class="layui-form-item">
            <input type="text" name="money" id="money" lay-verify="required" placeholder="请输入价格" class="layui-input">
        </div>
        <div class="layui-form-item">
            <input type="text" name="repairtype" lay-verify="required" placeholder="维修类型" class="layui-input">
        </div>
        <div class="layui-form-item">
            <input type="text" name="plotid" lay-verify="required" placeholder="小区" class="layui-input">
        </div>
        <div class="layui-form-item">
            <input type="text" name="position" lay-verify="required" placeholder="地址" class="layui-input">
        </div>
    </form>
</div>
<script>
    let $=layui.$;
    let table = layui.table;
    let laydate = layui.laydate;
    layui.use(["table","laydate"],function (){
        table.render({
            id:'leaders',
            elem:'#ID-table-demo-data',
            url:"/Repairs/selectAllRepairJob?employee="+"${sessionScope.loginUser.id}",
            toolbar:"#headTool",
            page:true,
            cols:[[
                {field:'number',align: 'center',type:'numbers',title:"编号"},
                {align: 'center',field:'id',hide:true,title:'编号'},
                {align: 'center',field: 'position',title: '报修位置'},
                {align: 'center',field: 'repairtype',title: '报修描述'},
                {align: 'center',field: 'repairpeople',title: '报修人'},
                {align: 'center',field: 'phone',title: '联系电话'},
                {align: 'center',field: 'plotname',title: '小区名称',templet(d) {
                        return d.plot==null?"-":d.plot.plotname
                    }},
                {align: 'center',field: 'hopetime',title: '预约时间',sort:true},
                {align: 'center',field: 'img',title: '照片',templet(d) {
                        return  d.img==null?"-":"<img src='/"+d.img+"' width='50px'/>";
                    }},
                {align: 'center',field: 'istype',title: '报修类型',templet(d) {
                        return d.istype==1?"居家维修":"公共维修";
                    }},
                {align: 'center',title: '员工',templet(d) {
                        return d.user == null ? "-" : d.user.username;
                    }},
                {title: '操作',toolbar:'#barDemo',width:200},
            ]]

        })

    })
    //点击查询
    function search(){
        var where=layui.form.val('searchForm');
        layui.table.reload('leaders', {
            page: {
                curr:1
            },
            where: where
        });
    }


    /***
     * 监听事件
     */
    table.on("tool(itemTable)",function (obj){
        if(obj.event=="finish"){
            finish(obj);
        }else if(obj.event=="repai"){
            repai(obj.data.id);
        }
    })
    function finish(obj){
        $("#updateStateForm")[0].reset();
        $("[name=repstateid]").val(3);
        $("[name=id]").val(obj.data.id);
        layui.form.val('updateStateForm',obj.data)
        let istype=obj.data.istype;
        if(istype==1){
            $("[name=money]").show()

        }else if(istype==2){
            $("[name=money]").hide();
        }


        layui.layer.open({
            type:1,
            title:"完成任务",
            area:["350px","300px"],
            content:$("#updateState"),
            btn:["确定","取消"],
            yes(){
                if(istype==1){
                    $("[name=money]").show()
                    let moneytext=$("[name=money]").val()
                    if(moneytext==null || moneytext==""){
                        alert("请填写价格");
                        return;
                    }
                }

                layui.form.val('addMoneyForm',obj.data)
                $("[name=plotid]").val(obj.data.plot.id)
                $("[name=repairtype]").val(obj.data.repairtype)
                $("#money").val($("#moneys").val())
                let addMoneyForm=layui.form.val("addMoneyForm");

                $.post("/Repairquotation/addQuotation",addMoneyForm).then((msg)=>{})
                let updateForm=layui.form.val("updateState");
                $.post("/Repairs/updateRepairs",updateForm).then(({msg})=>{
                    layui.layer.close(layui.layer.index);
                    layui.layer.msg(msg);
                    layui.table.reload('leaders')
                })
            }
        })
    }
    function repai(id){
        $("[name=stateid]").val(1);
        $("[name=id]").val(id);
        $("[name=employee]").val('')
        layui.layer.open({
            type:0,
            icon:3,
            area:["250px","200px"],
            title:"提示",
            content:"确定要退单吗？",
            btn:["确定","取消"],
            yes(){
                let updateForm=layui.form.val("updateState");
                $.post("/Repairs/updateEmployee",updateForm).then(({msg})=>{
                    layui.layer.close(layui.layer.index);
                    layui.layer.msg(msg);
                    layui.table.reload('leaders')
                })
            }
        })
    }
</script>
</body>
</html>
